package com.nio;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author zhuangqi
 * @date 2017/9/12.
 */
public class NioBufferWriteDemo {

    public static void main(String[] args) {
        try {
            FileOutputStream os = new FileOutputStream("E:\\test2.txt");
            FileChannel fc = os.getChannel();
            ByteBuffer buffer = ByteBuffer.allocate(1024);
            String message[] = {"liyuanpeng","yaoqingyuan"};
            for (int i=0; i<message.length; ++i){
                buffer.put(message[i].getBytes());
            }
            buffer.flip();
            fc.write(buffer);
            buffer.clear();
            fc.close();
            os.close();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
    }
}
